package com.simple.car.loader.server.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import com.simple.car.loader.server.manager.impl.BeamManager;
import com.simple.car.loader.server.tools.LocalTool;

public class RunningLocationService extends Service {

    private boolean isRegistered;

    private LocalTool localTool;

    public RunningLocationService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onCreate() {
        super.onCreate();
        localTool = (LocalTool) BeamManager.getInstance().lookup(LocalTool.class.getName());
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        int command = super.onStartCommand(intent, flags, startId);
        if (isRegistered) {
            return command;
        }
        localTool.register(this);
        return command;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (isRegistered) {
            localTool.unregister(this);
        }
    }
}